package codetop.microsoft.T386;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 18362
 * @Create: 2022-09-04 23:38:52 星期日
 */
class Solution {
    public List<Integer> lexicalOrder(int n) {
        List<Integer> res = new ArrayList<>();
        for (int i=0, j=1; i<n; ++i) {
            res.add(j);
            if (j * 10 <= n)
                j *= 10;
            else {
                while (j % 10 == 9 || j == n)
                    j /= 10;
                j++;
            }
        }
        return res;
    }
}